package bussinessService.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import module.BasicArea;
import module.BasicBanKuai;
import module.Unit;
import bussinessService.unitBussinessService;
import domain.vo.UnitVO;
import domain.vo.queryObject;
/**
 * 
* @ClassName: UnitBussinessServiceImpl 
* @Description: 小区业务层实现
* @author chenchao
* @date 2014年1月16日 下午1:13:47 
*
 */
public class UnitBussinessServiceImpl  implements unitBussinessService{


	public Unit getById(String id) throws SQLException {
		// TODO Auto-generated method stub
		return unitService.getById(id);
	}


	public List<UnitVO> getAll() throws SQLException {
		List<UnitVO>  vos  = new ArrayList<UnitVO>();
		List<Unit> results = new ArrayList<Unit>();
		results = unitService.getAll();
		for(Unit u : results) {
			UnitVO vo = new UnitVO();
			vo.setBlockId(u.getBlockId());
			BasicBanKuai bbk =   bbkService.getById(Integer.toString(u.getBlockId()));
			vo.setBlockName(bbk.getBb_name());
			vo.setDistrictId(u.getDistrictId());
			BasicArea ba = baService.getById(Integer.toString(u.getDistrictId()));
			vo.setDistrictName(ba.getBhaName());
			vo.setPingyin(u.getPingyin());
			vo.setPingyin2(u.getPingyin2());
			vo.setUnitId(u.getUnitId());
			vo.setUnitName(u.getUnitName());
			vo.setUnitAddress(u.getUnitAddress());
			vos.add(vo);
		}
		return vos;

	}


	public void merageObject(Unit t) throws SQLException {
		if(t.getUnitId() == 0) {
			unitService.insertObject(t);
		} else {
			unitService.updateObject(t);
		}
		
	}


	public void deleteT(int id) throws SQLException {
		// TODO Auto-generated method stub
		
	}


	public List<UnitVO> getObjectByQueryObject(queryObject queryObject)
			throws SQLException {
		List<UnitVO>  vos  = new ArrayList<UnitVO>();
		List<Unit> results = new ArrayList<Unit>();
		results = unitService.getObjectByQueryObject(queryObject);
		for(Unit u : results) {
			UnitVO vo = new UnitVO();
			vo.setBlockId(u.getBlockId());
			BasicBanKuai bbk =   bbkService.getById(Integer.toString(u.getBlockId()));
			vo.setBlockName(bbk.getBb_name());
			vo.setDistrictId(u.getDistrictId());
			BasicArea ba = baService.getById(Integer.toString(u.getDistrictId()));
			vo.setDistrictName(ba.getBhaName());
			vo.setPingyin(u.getPingyin());
			vo.setPingyin2(u.getPingyin2());
			vo.setUnitId(u.getUnitId());
			vo.setUnitName(u.getUnitName());
			vo.setUnitAddress(u.getUnitAddress());
			vos.add(vo);
		}
		return vos;
	}


	public int countByQueryObject(queryObject queryObject) throws SQLException {
		// TODO Auto-generated method stub
		return unitService.countByQueryObject(queryObject);
	}

}
